﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QuanLyDiem.models;
namespace QuanLyDiem.Controllers
{
    public class C_CTDaoTao
    {
        public static void LoadBindingSource(BindingSource binding, Context db = null)
        {
            if (db == null) db = new Context();
            binding.DataSource = db.ChuongTrinhDaoTaos.OrderBy(a => a.Ky_hoc).ToList();
        }
        public static bool Delete(ChuongTrinhDaoTao daotao, Context db = null)
        {
            if (db == null) db = new Context();
            var delete = db.ChuongTrinhDaoTaos.SingleOrDefault(a => a.Ky_hoc == daotao.Ky_hoc);
            if (delete == null) return false;
            db.ChuongTrinhDaoTaos.DeleteOnSubmit(delete);
            db.SubmitChanges();
            return true;
        }
        public static bool Update(ChuongTrinhDaoTao daotao, Context db = null)
        {
            if (db == null) db = new Context();
            var update = db.ChuongTrinhDaoTaos.SingleOrDefault(a => a.ID == daotao.ID);
            if (update == null) return false;
            update.Ky_hoc = daotao.Ky_hoc;
            update.ID_mon = daotao.ID_mon;
            update.ID_khoa = daotao.ID_khoa;
            db.SubmitChanges();
            return true;
 
        }

        public static bool Insert(ChuongTrinhDaoTao daotao, Context db = null)
        {
            if (db == null) db = new Context();
            db.ChuongTrinhDaoTaos.InsertOnSubmit(daotao);
            db.SubmitChanges();
            return true;
        }
    }
}
